using CodeSpirit.Core;
using CodeSpirit.ExamApi.Data.Models.Enums;
using CodeSpirit.Shared.Entities;
using System.ComponentModel.DataAnnotations;

namespace CodeSpirit.ExamApi.Data.Models;

/// <summary>
/// 试卷实体
/// </summary>
public class ExamPaper: LongKeyAuditableEntityBase, IMultiTenant
{    
    /// <summary>
    /// 试卷名称
    /// </summary>
    [Required]
    [StringLength(100)]
    public string Name { get; set; } = string.Empty;
    
    /// <summary>
    /// 试卷描述
    /// </summary>
    [StringLength(500)]
    public string? Description { get; set; }
    
    /// <summary>
    /// 试卷类型
    /// </summary>
    [Required]
    public ExamPaperType Type { get; set; }
    
    /// <summary>
    /// 总分（如果启用成绩换算，则为换算后的满分；否则为原始满分）
    /// </summary>
    [Required]
    [Range(0, 1000)]
    public int TotalScore { get; set; }
    
    /// <summary>
    /// 及格分数（如果启用成绩换算，则为换算后的及格分；否则为原始及格分）
    /// </summary>
    [Range(0, 1000)]
    public int PassScore { get; set; }
    
    /// <summary>
    /// 时长（分钟）
    /// </summary>
    [Range(1, 1440)]
    public int Duration { get; set; }
    
    /// <summary>
    /// 随机试卷规则，JSON格式（如题型分布、难度分布、知识点覆盖等）
    /// </summary>
    [StringLength(2000)]
    public string? RandomRules { get; set; }
    
    /// <summary>
    /// 试卷包含的题目
    /// </summary>
    public ICollection<ExamPaperQuestion> ExamPaperQuestions { get; set; } = [];
    
    /// <summary>
    /// 试卷难度系数（0-100）
    /// </summary>
    [Range(0, 100)]
    public int DifficultyLevel { get; set; }
    
    /// <summary>
    /// 试卷版本
    /// </summary>
    [Required]
    public int Version { get; set; } = 1;
    
    /// <summary>
    /// 使用次数
    /// </summary>
    public int UsageCount { get; set; } = 0;
    
    /// <summary>
    /// 平均分
    /// </summary>
    [Range(0, 1000)]
    public decimal AverageScore { get; set; } = 0;
    
    /// <summary>
    /// 通过率（百分比）
    /// </summary>
    [Range(0, 100)]
    public decimal PassRate { get; set; } = 0;
    
    /// <summary>
    /// 试卷状态
    /// </summary>
    public ExamPaperStatus Status { get; set; }
    
    /// <summary>
    /// 是否已完成预览检查
    /// </summary>
    public bool IsPreviewChecked { get; set; } = false;
    
    /// <summary>
    /// 是否启用成绩换算
    /// </summary>
    public bool EnableScoreConversion { get; set; } = false;

    /// <summary>
    /// 原始总分（换算前的满分，始终保存试卷的原始分值）
    /// </summary>
    [Range(1, 1000)]
    public int? OriginalTotalScore { get; set; }

    /// <summary>
    /// 原始及格分（换算前的及格分，始终保存试卷的原始及格分）
    /// </summary>
    [Range(0, 1000)]
    public int? OriginalPassScore { get; set; }

    /// <summary>
    /// 换算目标满分（换算后想要达到的满分）
    /// </summary>
    [Range(1, 1000)]
    public int? ConversionTargetFullScore { get; set; }

    /// <summary>
    /// 换算小数保留位数
    /// </summary>
    [Range(0, 2)]
    public int ConversionDecimalPlaces { get; set; } = 1;

    /// <summary>
    /// 换算比例（换算后满分/原始满分，使用decimal确保精度）
    /// </summary>
    public decimal? ConversionRatio { get; set; }
    
    /// <summary>
    /// 租户ID
    /// </summary>
    [Required]
    [StringLength(50)]
    public string TenantId { get; set; } = string.Empty;
}